package pokerantani.v2.linematchers;

import java.util.List;
import java.util.regex.Pattern;

import pokerantani.v2.LineMatcher;
import pokerantani.v2.RE;
import pokerantani.v2.model.Card;
import pokerantani.v2.model.GamePhase;


public class PhaseMark extends LineMatcher {
	static final Pattern pPreflopMark = Pattern.compile("\\*{3} HOLE CARDS \\*{3}");
	static final Pattern pFlop = Pattern.compile("\\*{3} FLOP \\*{3} \\[(" + RE.CARD + ") (" + RE.CARD + ") (" + RE.CARD + ")\\]");
	static final Pattern pTurn = Pattern.compile("\\*{3} TURN \\*{3} \\[" + RE.CARD + " " + RE.CARD + " " + RE.CARD + "\\] \\[(" + RE.CARD + ")\\]");
	static final Pattern pRiver = Pattern.compile("\\*{3} RIVER \\*{3} \\[" + RE.CARD + " " + RE.CARD + " " + RE.CARD + " " + RE.CARD + "\\] \\[(" + RE.CARD + ")\\]");
	static final Pattern pShowDown = Pattern.compile("\\*{3} SHOW DOWN \\*{3}");
	static final Pattern pSummary = Pattern.compile("\\*{3} SUMMARY \\*{3}");
	
	public GamePhase phase;
	public List<Card> cards;
	
	public boolean match(String line) {
		if(match(line, pPreflopMark)) {
			phase = GamePhase.PREFLOP;
			return true;
		}
		if(match(line, pFlop)) {
			phase = GamePhase.FLOP;
			cards = groupCards(1, 2, 3);
			return true;
		}
		if(match(line, pTurn)) {
			phase = GamePhase.TURN;
			cards = groupCards(1);
			return true;
		}
		if(match(line, pRiver)) {
			phase = GamePhase.RIVER;
			cards = groupCards(1);
			return true;
		}
		if(match(line, pShowDown)) {
			phase = GamePhase.SHOWDOWN;
			return true;
		}
		if(match(line, pSummary)) {
			phase = GamePhase.SUMMARY;
			return true;
		}
		return false;
	}
}
